package auth

import (
	"context"
	api "gf-vben-admin/api/auth/v1"
	"gf-vben-admin/internal/service/auth"
	"github.com/gogf/gf/v2/os/gtime"
)

type authController struct{}

var Auth = authController{}

func (c *authController) Login(ctx context.Context, req *api.AuthLoginReq) (res *api.AuthLoginRes, err error) {

	token, expire := auth.Auth().LoginHandler(ctx)
	res = &api.AuthLoginRes{
		Token:  token,
		Expire: *gtime.NewFromTime(expire),
	}

	return
}

func (c *authController) RefreshToken(ctx context.Context, req *api.AuthRefreshTokenReq) (res *api.AuthRefreshTokenRes, err error) {
	res = &api.AuthRefreshTokenRes{}
	res.Token, res.Expire = auth.Auth().RefreshHandler(ctx)
	return
}

func (c *authController) Logout(ctx context.Context, req *api.AuthLogoutReq) (res *api.AuthLogoutRes, err error) {
	auth.Auth().LogoutHandler(ctx)
	return
}
